
* LOAD DATA
use "C:\Users\suuser\Dropbox\Turkish Foreign Aid\empirics\2017-11 (replication data)\main data 2017-11-24.dta", clear


preserve

* keep only Turkish foreign aid
keep if turkey ==1

* drop observations where (1) the recipent is not a low/middle income country, or (2) the donor did not give any aid to any country in that year
keep if notinDAC ==0 & noaid_cyears ==0


* Define MACROS to make the code tidier
local depvar		"dvhigh dvlag"

local donor 		"c.donor_gdppc c.donor_gdpgrowth c.donor_victims"

local culturalties	"c.donor_lang_pct c.donor_relig_pct"

local needs			"c.recip_infantmort c.recip_gdppc"

local governance	"c.recip_polity2 c.recip_polterror"


* specify interaction variable: "AKP"
gen period_dummy =.
replace period_dummy = akp			

local combined		"i.period_dummy##(`culturalties' l(c.donor_exports c.un_vote_sim) l(`needs') c.recip_victims l(`governance') l(c.ln_distance c.recip_population) )"
		

**********************************************
* TABLE 1: Comparison of Turkish Governments *
**********************************************

* Column 1: Total Aid

* Prepare dependent variable
gen dvlow = ln_total_aid_dv
replace dvlow =. if ln_total_aid_dv <=0
gen dvhigh = ln_total_aid_dv
replace dvhigh =0 if dvhigh <0
gen dvlag = l.dvhigh


* Tobit regression (estimates saved, but not shown)
quietly: tobit `depvar' `combined' `donor' 			 	///
	, ll(0) vce(cluster ccode2) 
	est store tot_tr_tobit
	
* calculate MARG FX for every variable
margins, dydx(*) predict(ystar(0,.)) at(period_dummy=(0 1))	post
	est store tot_tr_margfx

* run regression again
quietly: tobit `depvar' `combined' `donor' 			 	///
	, ll(0) vce(cluster ccode2) 
	
* calculate P-VALUE for marginal effect of every variable
margins, dydx(*) predict(ystar(0,.)) at(period_dummy=(0 1)) contrast(atcontrast(r))	post
	est store tot_tr_pvalue

drop dv*


* Column 2: Economic Aid

* Prepare dependent variable
gen dvlow = ln_econ_aid_dv 
replace dvlow =. if ln_econ_aid_dv <=0
gen dvhigh = ln_econ_aid_dv 
replace dvhigh =0 if dvhigh <0
gen dvlag = l.dvhigh


* Tobit regression (estimates saved, but not shown)
quietly: tobit `depvar' `combined' `donor' 			 	///
	, ll(0) vce(cluster ccode2)
	est store ec_tr_tobit

* calculate MARG FX for every variable
margins, dydx(*) predict(ystar(0,.)) at(period_dummy=(0 1))	post
	est store ec_tr_margfx

* run regression again
quietly: tobit `depvar' `combined' `donor'				 	///
	, ll(0) vce(cluster ccode2)
	
* calculate P-VALUE for marginal effect of every variable
margins, dydx(*) predict(ystar(0,.)) at(period_dummy=(0 1)) contrast(atcontrast(r))	post
	est store ec_tr_pvalue

drop dv*


* Column 3: Humanitarian Aid

* Prepare dependent variable
tsset dyadnum year
gen dvlow = ln_human_aid_dv 
replace dvlow =. if ln_human_aid_dv <=0
gen dvhigh = ln_human_aid_dv 
replace dvhigh =0 if dvhigh <0
gen dvlag = l.dvhigh


* Tobit regression (estimates saved, but not shown)
quietly: tobit `depvar' `combined' `donor'			 	///
	, ll(0) vce(cluster ccode2)
	est store hum_tr_tobit

* calculate MARG FX for every variable
margins, dydx(*) predict(ystar(0,.)) at(period_dummy=(0 1))	post
	est store hum_tr_margfx

* run regression again
quietly: tobit `depvar' `combined' `donor' 			 	///
	, ll(0) vce(cluster ccode2)
	
* calculate P-VALUE for marginal effect of every variable
margins, dydx(*) predict(ystar(0,.)) at(period_dummy=(0 1)) contrast(atcontrast(r))	post
	est store hum_tr_pvalue
	
drop dv*


**********
* TABLES *
**********


* Produce TABLE 1 in article (Marginal Effects)
esttab tot_tr*fx ec_tr*fx hum_tr*fx, b(3) se(3) 			///
	mtitle noomit nobase noconstant wide compress


* List of P-VALUES for TABLE 1
estimates replay tot_tr_*pvalue	
estimates replay ec_tr_*pvalue	
estimates replay hum_tr_*pvalue		


* TOBIT REGRESSION TABLE (in the online appendix)
esttab *tr_tobit, b(3) se(3) stats(N ll) 	///
	mtitle noomit nobase noconstant compress varwidth(30)	
	
restore
